package com.wf.demo.info.util;

import com.wf.demo.sys.constant.CommonConstant;
import lombok.Data;

/**
 * @Auther: wf
 * @Date: 2019/12/9 14:24
 * @Description:
 */
@Data
public class Result<T> {

    private    Integer code;
    private    String message;
    /**
     * 返回数据对象 data
     */
    private T data;

    public Result() {

    }

    public Result<T> error500(String message) {
        this.message = message;
        this.code = CommonConstant.SC_INTERNAL_SERVER_ERROR_500;

        return this;
    }

    public Result<T> success(String message) {
        this.message = message;
        this.code = CommonConstant.SC_OK_200;
        return this;
    }
    //添加更新对象失败，
    public static Result<Object> addFail(String message) {
        Result<Object> r = new Result<Object>();
        r.message = message;
        r.code = CommonConstant.Add_FAIL_CODE;
        return r;
    }
    //添加更新对象成功，
    public static Result<Object> addSuccess(Object object) {
        Result<Object> r = new Result<Object>();
        r.setCode(CommonConstant.Add_SUCCESS_CODE);
        r.setData(object);
        return r;
    }
    //搜索成功，
    public static Result<Object>searchSuccess(Object object) {
        Result<Object> r = new Result<Object>();
        r.setCode(CommonConstant.Search_Success_code);
        r.setData(object);
        return r;
    }
    //搜索失败，
    public static Result<Object>searchFail(String msg) {
        Result<Object> r = new Result<Object>();
        r.setCode(CommonConstant.Search_Fail_code) ;
        r.setMessage(msg);
        return r;
    }
    public static Result<Object> ok() {
        Result<Object> r = new Result<Object>();
        r.setCode(CommonConstant.SC_OK_200);
        r.setMessage("成功");
        return r;
    }

    public static Result<Object> ok(String msg) {
        Result<Object> r = new Result<Object>();

        r.setCode(CommonConstant.SC_OK_200);
        r.setMessage(msg);
        return r;
    }

    public static Result<Object> ok(Object data) {
        Result<Object> r = new Result<Object>();

        r.setCode(CommonConstant.SC_OK_200);
        r.setData(data);
        return r;
    }


    public static Result<Object> error(String msg) {
        return error(CommonConstant.SC_INTERNAL_SERVER_ERROR_500, msg);
    }

    public static Result<Object> error(int code, String msg) {
        Result<Object> r = new Result<Object>();
        r.setCode(code);
        r.setMessage(msg);
        return r;
    }
    public static Result<Object> ok(int code, String msg) {
        Result<Object> r = new Result<Object>();
        r.setCode(code);
        r.setMessage(msg);
        return r;
    }


}
